home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 3.1 KB | 116 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPrfCnt.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifdef FW_PROFILE
-
- #ifndef FWPRFCNT_H
- #include "FWPrfCnt.h"
- #endif
-
- #include <string.h>
-
- #pragma segment FWDebug_PerformanceCounter
-
-
- //========================================================================================
- // CLASS FW_CPrivPerformanceCounter
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
- DWORD FW_CPrivPerformanceCounter::gWinOverhead = (DWORD) -1;
- DWORD FW_CPrivPerformanceCounter::gWinFreq = 0;
- #endif
-
- #ifdef FW_BUILD_MAC
- const long kMacMaxInterval = -60l * 1000l * 1000l; // microseconds: 1 minute
-
- long FW_CPrivPerformanceCounter::gMacTMOverhead = -1;
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPerformanceCounter::FW_CPrivPerformanceCounter
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPerformanceCounter::FW_CPrivPerformanceCounter() :
- fResult(-1)
- {
- #ifdef FW_BUILD_WIN
- ::QueryPerformanceCounter(&fWinBegin);
-
- // Determine the overhead
- if (gWinOverhead == (DWORD) -1)
- {
- ::QueryPerformanceCounter(&fWinEnd);
- gWinOverhead = fWinEnd.LowPart - fWinBegin.LowPart;
-
- // Get the resolution
- LARGE_INTEGER liFreq;
- ::QueryPerformanceFrequency(&liFreq);
- gWinFreq = liFreq.LowPart;
-
- ::QueryPerformanceCounter(&fWinBegin);
- }
- #endif
- #ifdef FW_BUILD_MAC
- ::memset(&fMacTMTask, 0, sizeof(fMacTMTask));
- ::InsTime((QElemPtr) &fMacTMTask);
- ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
-
- // Determine the overhead
- if (gMacTMOverhead == -1)
- {
- ::RmvTime((QElemPtr) &fMacTMTask);
- gMacTMOverhead = fMacTMTask.tmCount - kMacMaxInterval;
-
- ::InsTime((QElemPtr) &fMacTMTask);
- ::PrimeTime((QElemPtr) &fMacTMTask, kMacMaxInterval);
- }
-
- fMacIsInQueue = TRUE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPerformanceCounter::~FW_CPrivPerformanceCounter
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPerformanceCounter::~FW_CPrivPerformanceCounter()
- {
- #ifdef FW_BUILD_MAC
- if (fMacIsInQueue)
- ::RmvTime((QElemPtr) &fMacTMTask);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPerformanceCounter::EndCheckPoint
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivPerformanceCounter::EndCheckPoint()
- {
- #ifdef FW_BUILD_WIN
- ::QueryPerformanceCounter(&fWinEnd);
- fResult = fWinEnd.LowPart - fWinBegin.LowPart - gWinOverhead;
- #endif
- #ifdef FW_BUILD_MAC
- FW_ASSERT(fMacIsInQueue);
- ::RmvTime((QElemPtr) &fMacTMTask);
- fMacIsInQueue = FALSE;
- fResult = fMacTMTask.tmCount - kMacMaxInterval - gMacTMOverhead;
- #endif
- }
-
- #endif
-